package com.situ.hospital.room.service;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.situ.hospital.room.dao.IRoomDao;
import com.situ.hospital.room.dao.impl.RoomDaoImpl;
import com.situ.hospital.room.model.RoomModel;

public class RoomService {
private IRoomDao dd=new RoomDaoImpl();
	
	public List<RoomModel> select(RoomModel room) throws SQLException {
		String name=room.getDepartmentName();
		room.setDepartmentName(name==null?"%%":"%"+name+"%");
		String address=room.getRoomAddress();
		room.setRoomAddress(address==null?"%%":"%"+address+"%");
		room.setId(1);
		return dd.selectAll(room);
	}

	public Integer add(RoomModel room) throws SQLException {
		RoomModel rm=new RoomModel();
		rm.setRoomId(room.getRoomId());
		RoomModel dm1=dd.selectModel(rm);
		return dm1==null?dd.insert(room):3;
	}

	public Integer del(RoomModel room) throws SQLException {
		return dd.deleteById(room);
	}

	public Map<String,Object> selectModel(RoomModel room) throws SQLException {
		Map<String,Object> map=new HashMap<>();
		map.put("selectmodel", dd.selectModel(room));
		return map;
	}

	public Integer update(RoomModel room) throws SQLException {
		return dd.updateById(room);
	}

	public int selectCount(RoomModel room) throws SQLException {
		RoomModel rm=new RoomModel();
		String name=room.getDepartmentName();
		rm.setDepartmentName(name==null?"%%":"%"+name+"%");
		String address=room.getRoomAddress();
		rm.setRoomAddress(address==null?"%%":"%"+address+"%");
		rm.setId(1);
		return dd.selectCount(rm);
	}
}
